package de.dhbw.karlsruhe.picsim.gui.renderer;

import de.dhbw.karlsruhe.picsim.gui.data.OpCodeGui;

import javax.swing.*;
import javax.swing.table.DefaultTableCellRenderer;
import java.awt.*;

/**
 * Created by IntelliJ IDEA.
 * User: goesen
 * Date: Apr 22, 2010
 * Time: 9:06:23 PM
 */

abstract class ProgramRenderingSupport extends DefaultTableCellRenderer {

    @Override
    @SuppressWarnings({"ReturnOfThis"})
    public final Component getTableCellRendererComponent(final JTable table, final Object value,
                                                         final boolean isSelected,
                                                         final boolean hasFocus, final int row, final int column) {

        super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
        if (value instanceof OpCodeGui) {
            final OpCodeGui opCodeGui = (OpCodeGui) value;
            setBackground(opCodeGui.isCurrentAddress() ? Color.GREEN : Color.white);

            return getRenderingComponent(opCodeGui, table, row, column);
        }
        return this;
    }

    protected abstract JComponent getRenderingComponent(final OpCodeGui opcode, final JTable jtable, final int row,
                                                        int column);
}
